home *** CD-ROM | disk | FTP | other *** search
- /********************************************** palette_event.c *********
- *
- * Notes from hsc%vanderbilt@csnet-relay
- * Date: 7/1/87
- *
- * Based on the version provided by the SunMicrosystem, Inc., the
- * following features have been added to the palettetool:
- *
- * 1) MS_RIGHT: it paints the "selected color" over the
- * colors through to the color selected by RM.
- * 2) MS_MIDDLE: this button reverses, or undoes, the last
- * RM.
- * 3) box lock: the box is locked when the LM is pressed.
- * Another LM or MM/RM will unlock the lock.
- * This is intended to leave the box at the
- * color when the mouse is been moved to the
- * control panel. Caution: the user should
- * allow time to let the box catch up the
- * motion of the mouse, especially when the
- * mouse is moved from outside of the multiple-
- * canvas.
- * 4) single_canvas: the layout of the single_canvas has been
- * changed to contain a colormap stripe reflecting
- * the current colormap setting. The motion of the
- * cursor within the single_canvas is traced by
- * an arrow pointing at the colormap entry the mouse
- * resides, together with the colormap entry number
- * displayed. A RM will select that color and lock
- * the box at the corresponding color in the
- * multiple_canvas. The user may then move the
- * mouse to the control panel and, if so wish,
- * change that color. Pressing Reset button will
- * reset that color to its previous value before
- * the change.
- */
- #include "p_include.h"
-
-
- oid
- isplay_event_proc(canvas, event, arg)
- Canvas canvas;
- Event *event;
- caddr_t arg;
- {
- int pix;
-
- if (event_is_button(event)) {
- pix = pw_get(canvas_pixwin(canvas), event_x(event), event_y(event));
-
- advance_arrow(pix);
-
- /*
- * fake a notifier procedure call to draw a
- * box over the corresponding color on the
- * multiple_canvas
- */
- selected = FALSE;
- event_set_id(event, LOC_MOVE);
- event_set_x(event, (pix % 24) * (cwidth + xspace) + xoff);
- event_set_y(event, (pix / 24) * (cheight + yspace) + yoff);
- multiple_canvas_event_proc(multiple_canvas, event, arg);
- /*
- * fake another notifier procedure call to
- * lock the box over the chosen color on
- * the multiple_canvas
- */
- event_set_id(event, MS_LEFT);
- multiple_canvas_event_proc(multiple_canvas, event, arg);
- }
- }
-
- oid
- ultiple_canvas_event_proc(m_canvas, event, arg)
- Window m_canvas;
- Event *event;
- caddr_t arg;
- {
- int x, y, i, j, x0, x1, y0, y1, hx0, hx1, hy0, hy1;
- int in_a_box, in_a_new_box;
- float m, n;
- Pixwin *pw;
-
- x = event_x(event);
- y = event_y(event);
-
- m = (x - xoff) / (cwidth + xspace);
- n = (y - yoff) / (cheight + yspace);
- i = (int) m;
- j = (int) n;
-
- pw = (Pixwin *) canvas_pixwin(m_canvas);
-
- /*
- * trace the mouse motion and draw a box around the
- * color panel pointed by the mouse brush trace is
- * stopped when the LM is pressed, i.e., user has
- * selected a color to modify and is on his way to
- * the control panel (box sould not follow the
- * mouse when it's on its way to the control panel)
- */
- if (event_id(event) == LOC_MOVE && !selected) {
- x0 = xoff + i * (cwidth + xspace);
- y0 = yoff + j * (cheight + yspace);
- x1 = x0 + cwidth;
- y1 = y0 + cheight;
-
- in_a_box = ((m - i) * (cwidth + xspace) <= cwidth &&
- (n - j) * (cheight + yspace) <= cheight &&
- i < 24 && j < 11);
- in_a_new_box = (in_a_box && (i != hi || j != hj));
-
- if (in_a_new_box) { /* inside a box */
- if (hi >= 0) { /* erase old box */
- hx0 = xoff + hi * (cwidth + xspace);
- hy0 = yoff + hj * (cheight + yspace);
- hx1 = hx0 + cwidth;
- hy1 = hy0 + cheight;
- draw_a_box(pw, hx0 - 3, hy0 - 3, hx1 + 3, hy1 + 3, BGCOLOR);
- }
- draw_a_box(pw, x0 - 3, y0 - 3, x1 + 3, y1 + 3, FGCOLOR); /* draw new box */
- advance_arrow(ijton(i, j));
- hi = i;
- hj = j;
- highlighted = 1;
- } else { /* outside a box */
- if (highlighted && (hi != i || hj != j) && hi >= 0) {
- hx0 = xoff + hi * (cwidth + xspace);
- hy0 = yoff + hj * (cheight + yspace);
- hx1 = hx0 + cwidth;
- hy1 = hy0 + cheight;
- draw_a_box(pw, hx0 - 3, hy0 - 3, hx1 + 3, hy1 + 3, BGCOLOR);
- advance_arrow(ijton(i, j));
- highlighted = 0;
- }
- }
- }
- /*
- * when the LM is pressed, the mouse box is frozen
- * at wherever it currently resides, so the user
- * should allow time to let the box catch up the
- * motion of the mouse, i.e., the box should
- * confine the brush.
- */
- if (event_id(event) == MS_LEFT && event_is_down(event) && highlighted) {
- selected = !selected;
- selected_i = i;
- selected_j = j;
- selected_n = ijton(i, j);
- panel_set_value(red_slider, r[selected_n]);
- panel_set_value(green_slider, g[selected_n]);
- panel_set_value(blue_slider, b[selected_n]);
- old_r = r[selected_n];
- old_g = g[selected_n];
- old_b = b[selected_n]; /* save the overwritten
- * color for Reset */
- }
- /*
- * right-mouse-paint undo procedure
- */
- if (event_id(event) == MS_MIDDLE && event_is_down(event)) {
- unsigned tmp[3][MAX_CMAP_LEN];
- int i;
-
- selected = FALSE;
- if (undo_len == 0) {
- post_msg("Nothing to be undone");
- return;
- }
- for (i = 0; i < undo_len; i++) {
- tmp[0][i] = undo_r[i];
- tmp[1][i] = undo_g[i];
- tmp[2][i] = undo_b[i];
- undo_r[i] = r[i + undo_start];
- undo_g[i] = g[i + undo_start];
- undo_b[i] = b[i + undo_start];
- r[i + undo_start] = tmp[0][i];
- g[i + undo_start] = tmp[1][i];
- b[i + undo_start] = tmp[2][i];
- }
- put_colors(undo_start, undo_len + 1, &r[undo_start], &g[undo_start],
- &b[undo_start]);
- }
- /*
- * copy color from selected_n through to that
- * pointed by the the right mouse button press
- */
- if (event_id(event) == MS_RIGHT && event_is_down(event)) {
- int n = ijton(i, j);
-
- selected = FALSE;
- if (n >= 0 && n < MAX_CMAP_LEN && n != selected_n) {
- int i;
-
- if (event_ctrl_is_down(event)) {
- /*
- * paint the selected_n
- * color to pointed color
- */
- undo_start = n;
- undo_len = 1;
- } else {
- /*
- * paint the selected_n
- * color through to pointed
- * color
- */
- undo_start = (n > selected_n) ? (selected_n + 1) : n;
- undo_len = abs(n - selected_n);
- }
-
- /*
- * save the overwitten part for
- * undo
- */
- pw_setcmsname(pw, CMAP_NAME);
- pw_getcolormap(pw, undo_start, undo_len, undo_r, undo_g, undo_b);
-
- /* do the right-mouse paint */
- for (i = 0; i < undo_len; i++) {
- r[undo_start + i] = r[selected_n];
- g[undo_start + i] = g[selected_n];
- b[undo_start + i] = b[selected_n];
- }
- put_colors(undo_start, undo_len,
- &r[undo_start], &g[undo_start], &b[undo_start]);
- post_msg("Colors copied from LM through to RM. Press MM to undo");
- }
- }
- }
-
-
- oid
- ingle_canvas_event_proc(s_canvas, event, arg)
- Window s_canvas;
- Event *event;
- caddr_t arg;
- {
- int y;
- Pixwin *spw;
-
- if (event_id(event) == MS_MIDDLE && event_is_down(event)) {
- selected = FALSE;
- return;
- }
- y = (event_y(event) - bar_offset) / 3;
- if (y >= MAX_CMAP_LEN || selected == TRUE)
- return;
- spw = canvas_pixwin(s_canvas);
- entry_id(spw, y);
- advance_arrow(y);
- if (event_id(event) == MS_LEFT && event_is_down(event)) {
- entry_id(spw, y);
- advance_arrow(y);
- /*
- * fake a notifier procedure call to draw a
- * box over the corresponding color on the
- * multiple_canvas
- */
- selected = FALSE;
- event_set_id(event, LOC_MOVE);
- event_set_x(event, (y % 24) * (cwidth + xspace) + xoff);
- event_set_y(event, (y / 24) * (cheight + yspace) + yoff);
- multiple_canvas_event_proc(multiple_canvas, event, arg);
- /*
- * fake another notifier procedure call to
- * lock the box over the chosen color on
- * the multiple_canvas
- */
- event_set_id(event, MS_LEFT);
- multiple_canvas_event_proc(multiple_canvas, event, arg);
- }
- }
-